package com.forusers.escrevecheque.client;

import java.util.Calendar;

import com.google.gwt.user.client.Random;

public class PortugueseDate {
	private static final String[] months = new String[] {
		"",
		"janeiro",
		"fevereiro",
		"março",
		"abril",
		"maio",
		"junho",
		"julho",
		"agosto",
		"setembro",
		"outubro",
		"novembro",
		"dezembro",
	};
	private static final String[] dow = new String[] {
		"segunda feira",
		"terça feira",
		"quarta feira",
		"quinta feira",
		"sexta feira",
		"sábado",
		"domingo",
	};

	public PortugueseDate() {
		cal = Calendar.getInstance();
		cal.add(Calendar.DAY_OF_MONTH, Random.nextInt(365));
	}

	public PortugueseDate(int year, int month, int day) {
		cal = Calendar.getInstance();
		cal.set(year, month - 1, day);
	}

	public PortugueseDate(long seed) {
		cal = Calendar.getInstance();
		java.util.Random rand = new java.util.Random(seed);
		cal.add(Calendar.DAY_OF_MONTH, rand.nextInt(365));
	}

	public String getLongDate() {
		return getDate(cal.get(Calendar.YEAR), 
				cal.get(Calendar.MONTH) + 1, 
				cal.get(Calendar.DAY_OF_MONTH));
	}
	
	public String getShortDate() {
		return getShortDate(cal.get(Calendar.YEAR), 
				cal.get(Calendar.MONTH) + 1, 
				cal.get(Calendar.DAY_OF_MONTH));
	}
	
	/**
	 * 
	 * @param year ex. 2009
	 * @param month 1-12
	 * @param day 1-31
	 * @return
	 */
	String getShortDate(int year, int month, int day) {
		StringBuffer buf = new StringBuffer();
		buf.append(day);
		buf.append("/");
		buf.append(month);
		buf.append("/");
		buf.append(year);
		return buf.toString();
	}

	/**
	 * 
	 * @param year ex. 2009
	 * @param month 1-12
	 * @param day 1-31
	 * @return
	 */
	String getDate(int year, int month, int day) {
		StringBuffer buf = new StringBuffer();
		
		buf.append(day);
		buf.append(" de ");
		buf.append(months[month]);
		buf.append(" de ");
		buf.append(year);
		
		return buf.toString();
	}
	
	private Calendar cal;
}
